/**
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Autogenerated file -- DO NOT EDIT!

inline bool NeedSafePointAfterIntrinsic(RuntimeInterface::IntrinsicId intrinsic) {
    switch (intrinsic) // NOLINT(hicpp-multiway-paths-covered)
    {
% Compiler::intrinsics.select {|intrinsic| intrinsic.safepoint_after_call}.each do |intrinsic|
    case ark::compiler::RuntimeInterface::IntrinsicId::<%= intrinsic.entrypoint_name %>:
        return true;
% end
    default:
        return false;
    }
}

#ifndef ONLY_NEEDSAFEPOINT
template <bool IS_VIRTUAL>
void InstBuilder::AddArgNullcheckIfNeeded([[maybe_unused]] RuntimeInterface::IntrinsicId intrinsic,
                                          [[maybe_unused]] Inst *inst, [[maybe_unused]] Inst *saveState,
                                          [[maybe_unused]] size_t bcAddr)
{
% if Compiler::intrinsics.any? {|intrinsic| !intrinsic.need_nullcheck.empty?}
    constexpr int ARG_OFFSET = IS_VIRTUAL ? 1 : 0;
    // NOLINTNEXTLINE(hicpp-multiway-paths-covered)
    switch (intrinsic)
    {
% Compiler::intrinsics.select {|intrinsic| !intrinsic.need_nullcheck.empty?}.each do |intrinsic|
    case ark::compiler::RuntimeInterface::IntrinsicId::<%= intrinsic.entrypoint_name %>:
% intrinsic.need_nullcheck.each do |arg_num|
        {
            auto nullCheck = graph_->CreateInstNullCheck(DataType::REFERENCE, bcAddr, inst->GetInput(ARG_OFFSET + <%= arg_num %>).GetInst(), saveState);
            inst->SetInput(ARG_OFFSET + <%= arg_num %>, nullCheck);
            AddInstruction(nullCheck);
        }
% end
        break;
% end
    default:
        break;
    }
% end
}

// NOLINTNEXTLINE(misc-definitions-in-headers, readability-function-size)
inline bool IsVirtual([[maybe_unused]] RuntimeInterface::IntrinsicId intrinsic)
{
% if Compiler::intrinsics.any? {|intrinsic| !intrinsic.static}
    switch (intrinsic)
    {
% Compiler::intrinsics.select {|intrinsic| intrinsic.has_impl? && !intrinsic.static}.each do |intrinsic|
    case ark::compiler::RuntimeInterface::IntrinsicId::<%= intrinsic.entrypoint_name %>:
        return true;
% end
    default:
        return false;
    }
% else
    return false;
% end
}

// NOLINTNEXTLINE(misc-definitions-in-headers)
template <Opcode OPCODE, bool IS_RANGE, bool ACC_READ, bool HAS_SAVE_STATE>
void InstBuilder::BuildCallHelper<OPCODE, IS_RANGE, ACC_READ, HAS_SAVE_STATE>::BuildVirtualCallIntrinsic(RuntimeInterface::IntrinsicId intrinsicId)
{
% if Compiler::ext_intrinsic_spaces.any?
    // NOLINTNEXTLINE(hicpp-multiway-paths-covered)
    switch (intrinsicId) {
#include "intrinsics_ir_build_virtual_call.inl"
        default: {
% end
            return BuildDefaultVirtualCallIntrinsic(intrinsicId);  // not supported case
% if Compiler::ext_intrinsic_spaces.any?
        }
    }
% end
}
#endif
